﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using canthovieclam.BL.DataContact.Filter;
using canthovieclam.BL.Models;
using canthovieclam.DAL.Repositories;

namespace canthovieclam.BL
{
    public class EmployerImpl
    {
        public void AddEmployer(EmployerModel employerModel)
        {
            var employerRepository = new EmployerRepository();
            employerRepository.AddEmployer(employerModel.MapEmployer());
            employerRepository.Commit();
        }

        public List<EmployerModel> GetEmployerModelList(EmployerFilter employerFilter)
        {
            var employerRepository = new EmployerRepository();
            List<EmployerModel> employerModelList = (from x in employerRepository.GetAllEmployer()
                                                    select new EmployerModel(x)).ToList();
            if (employerFilter != null)
            {
                if (employerFilter.FilterByEmployerStatus != null && employerFilter.FilterByEmployerStatus.Count > 0)
                {
                    var listValue = employerFilter.FilterByEmployerStatus.Cast<int>().ToList();
                    employerModelList = employerModelList.Where(x => listValue.Contains(x.State.Value)).ToList();
                }
            }
            return employerModelList;
        }
    }
}
